<template>
  <div class="about">
    <div class="my-list">
      <h1>干货集中营</h1>
      <div class="my-card" v-for="(item,index) of todos" :key="index">
        <div class="my-img"><img :src='item.url' alt=""></div>
        <div class="desc">
          {{ item.desc}}
        </div>
        <div>
          作者:{{item.author}}
          日期:{{item.createdAt}}
        </div>
      </div>
      <div>
        <button @click="decList">上一页</button>
        <button @click="AddList">下一页</button>
      </div>
    </div>
  </div>
</template>
<script>
  import http from "axios";
  export default {
    name: "GanHuo",
    data() {
      return {
        todos: {},
        page: 1,
      }
    },
    created() {
      this.GetList()
    },
    methods: {
      //发送axios请求
      GetList() {
        http({
          url: `https://gank.io/api/v2/data/category/Girl/type/Girl/page/${this.page}/count/10`,
        }).then(res => {
          this.todos = res.data.data
          console.log(res);
        })
      },
      AddList() {
        this.page += 1
        this.GetList()
      },
      decList() {
        if (this.page > 1) {
          this.page -= 1
          this.GetList()
        }
      },
    }
  };
</script>
<style scoped>
  .my-list {
    margin: 0 auto;
    width: 600px;
    height: 100%;
    border: 1px solid green;
  }

  .my-card img {
    width: 400px;
    object-fit: cover;
  }
</style>